class Solution {
public:
    bool isPalindrome(int x) {
        if (x<0 || (x%10==0 && x!=0)) return false;  // 排除负数和零结尾
        int reverted = 0;       // reverted the lower half
        while (x > reverted) {  // no chance for overflow
            reverted = reverted * 10 + x % 10;
            x /= 10;
        }
        // 奇数可以除掉最后一位
        return x == reverted || x == reverted / 10;  // even and odd
    }
};
